package com.bsj.travel.system.factory;

import com.bsj.travel.def.global.JsonResult;
import com.bsj.travel.def.global.JsonResultEnum;
import com.bsj.travel.system.RemoteUserService;
import com.bsj.travel.def.common.VO.TokenUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @author yinhao
 * @version 1.0
 * @description 用户服务降级处理
 * @date 2023/11/2
 */
@Component
@Slf4j
public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserService> {

    @Override
    public RemoteUserService create(Throwable cause) {
        log.info("用户服务调用失败: {}", cause.getMessage());
        return new RemoteUserService() {
            @Override
            public JsonResult<TokenUser> queryUserByName(String userName, String source) {
                return JsonResult.fail(JsonResultEnum.NOT_USER_INFO_ERROR, cause.getMessage());
            }
        };
    }
}
